package com.hzlx.service.impl;/*
 *@author liu
 *2024/07/2024/7/25
 *@version
 */

import com.hzlx.common.ResponseBean;
import com.hzlx.entity.CustomerAccount;
import com.hzlx.entity.CustomerBankCard;
import com.hzlx.entity.CustomerInfo;
import com.hzlx.mapper.CustomerAccountMapper;
import com.hzlx.service.CustomerAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpSession;
import java.util.Collections;
import java.util.List;

/**
 * @Author UP
 * @Date 2024/7/25 14:36
 * @Version 1.0
 **/
@Service
public class CustomerAccountServiceImpl implements CustomerAccountService {
    @Autowired
    private CustomerAccountMapper customerAccountMapper;
    @Autowired
    private HttpSession session;

    @Override
    public void getCustomerAccount(Model model) {
        CustomerInfo customerInfo = (CustomerInfo) session.getAttribute("customer");

        if (customerInfo != null) {
            Integer id = customerInfo.getId();
            List<CustomerAccount> customerAccountList = customerAccountMapper.getCustomerAccount(id);

            model.addAttribute("customerAccountList", customerAccountList);
            model.addAttribute("id", id);
        }
    }

    @Override
    public void getCustomerBankCard(Model model) {
        CustomerInfo customerInfo = (CustomerInfo) session.getAttribute("customer");
        if (customerInfo != null) {
            Integer id = customerInfo.getId();
            List<CustomerBankCard> customerBankCard = customerAccountMapper.getCustomerBankCard(id);
            model.addAttribute("customerBankCard", customerBankCard);
        }
    }

    @Override
    public ResponseBean getBalanceByCustomerId(Integer customerId) {
        if (customerId == null) {
            return new ResponseBean(10011, "获取余额信息失败", null);
        }
        CustomerAccount customerAccount = customerAccountMapper.getBalanceByCustomerId(customerId);
        if (customerAccount != null) {
            return new ResponseBean(0, "success", customerAccount);
        }
        return new ResponseBean(10012, "获取为空", null);
    }
}
